<?php

namespace app\api\model;

class Product extends BaseModel
{
	//'pivot'字段是多对多关系的中间表。TP5自动生成的
	protected $hidden = ['delete_time','main_img_id','pivot','from','category_id','create_time', 'update_time'];

	public function getMainImgUrlAttr($value, $data){
		return $this->prefixImgUrl($value, $data);
	}

	public static function getMostRecent($count){
		$products = self::limit($count)
					->order('create_time','DESC')
					->select();
		return $products;
	}

	public static function getProductsByCategoryID($categoryID){
		$products = self::where('category_id', '=', $categoryID)
					->select();
		return $products;
	}
}
